//
// Created by 11510 on 2024/6/12.
//

#ifndef DAY52_STRING_H
#define DAY52_STRING_H
#include <iostream>



class String{
public:
    String();

    String(const char *str);
    String(const String &str);
    ~String();
    void print();

    String &operator=(const String & rhs);
    String &operator=(const char * rhs);

    String &operator+=(const String &rhs);
    String &operator+=(const char *rhs);

    char &operator[](std::size_t index);
    const char &operator[](std::size_t index) const;

    std::size_t size() const;
    const char* c_str() const;

    friend bool operator==(const String &lhs, const String &rhs);
    friend bool operator!=(const String &lhs, const String &rhs);

    friend bool operator<(const String &lhs, const String &rhs);
    friend bool operator>(const String &lhs, const String &rhs);
    friend bool operator<=(const String &lhs, const String &rhs);
    friend bool operator>=(const String &lhs, const String &rhs);

    friend std::ostream &operator<<(std::ostream &os, const String &s);
    friend std::istream &operator>>(std::istream &is, String &s);

private:
    char * _pstr;
};

bool operator==(const String &lhs, const String &rhs);
bool operator!=(const String &lhs, const String &rhs);

bool operator<(const String &lhs, const String &rhs);
bool operator>(const String &lhs, const String &rhs);
bool operator<=(const String &lhs, const String &rhs);
bool operator>=(const String &lhs, const String &rhs);

std::ostream &operator<<(std::ostream &os, const String &s);
std::istream &operator>>(std::istream &is, String &s);


/**
 * NOTICE：这三个是非友元
 * @param lhs
 * @param rhs
 * @return
 */
String operator+(const String &lhs, const String &rhs);
String operator+(const String &lhs, const char *rhs);
String operator+(const char *lhs, const String &rhs);


#endif //DAY52_STRING_H
